/**
 * 
 */
package cn.ad.param;

import cn.ad.enumration.CampaignTagFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 订单查询参数
 * 
 * @author yujuan.zhang
 * @from 2016-06-13
 * @since V1.0
 *
 */
public class CampaignQuery extends AbstractPagingSortParam {

	private Integer tag;

	private Integer agencyId;

	private Integer advertiserId;

	private String search;

	public Integer getTag() {
		return tag;
	}

	public void setTag(Integer tag) {
		this.tag = tag;
	}

	public Integer getAgencyId() {
		return agencyId;
	}

	public void setAgencyId(Integer agencyId) {
		this.agencyId = agencyId;
	}

	public Integer getAdvertiserId() {
		return advertiserId;
	}

	public void setAdvertiserId(Integer advertiserId) {
		this.advertiserId = advertiserId;
	}

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

	/**
	 * 默认按id排序
	 */
	@Override
	public String getSortby() {
		return StringUtils.isEmpty(super.getSortby()) ? "id" : super.getSortby();
	}

	/**
	 * 默认按降序排序
	 */
	@Override
	public ORDER getOrder() {
		return super.getOrder() == null ? ORDER.desc : super.getOrder();
	}

	@JsonIgnore
	public Map<String,Object> getSearchMap(){
		Map<String,Object> map=new HashMap<>();
		map.put("tag",(this.tag==null||this.tag==0)?null: CampaignTagFormat.forValues(this.tag));
		map.put("agencyId",(this.agencyId==null||this.agencyId==0)?null:this.agencyId);
		map.put("advertiserId",(this.advertiserId==null||this.advertiserId==0)?null:this.advertiserId);
		map.put("search",this.search);
		map.put("offset",this.getOffset());
		map.put("limit",this.getLimit());
		map.put("order",this.getOrder());
		map.put("sortBy",this.getSortby());
		return map;
	}

}
